package com.machuxin.course.patterns.prototype;

import java.util.ArrayList;
import java.util.List;

public class Test {

    public static void main(String[] args) {
//        PersonPrototype p1 = new PersonPrototype();
//        p1.setAge(11);
//        p1.setName("a");
//        List<String> list = new ArrayList<>();
//        list.add("画画");
//        list.add("书法");
//        p1.setHobbies(list);
//        PersonPrototype p2 = p1.clone();
//        p2.setName("b");
//        System.out.println(p1);
//        System.out.println(p2);
//        p1.getHobbies().add("钢琴");
//        System.out.println(p1);
//        System.out.println(p2);
        PersonDeepPrototype  p1 = new PersonDeepPrototype();
        p1.setAge(11);
        p1.setName("a");
        List<String> list = new ArrayList();
        list.add("画画");
        list.add("书法");
        p1.setHobbies(list);
        PersonDeepPrototype p2 = p1.deepClone();
        p2.setName("b");
        System.out.println(p1);
        System.out.println(p2);
        p1.getHobbies().add("钢琴");
        System.out.println(p1);
        System.out.println(p2);


    }
}
